import { Fragment } from '@/components/Fragment'; import { Flex, Image, ScrollView, Link } from '@aws-amplify/ui-react'; import { ScrollViewDemo } from './demo'; import { AccessibleScrollViewExample, DefaultScrollViewExample, ScrollViewHorizontalExample, ScrollViewStylePropsExample, ScrollViewVerticalExample, } from './examples'; import { Example, ExampleCode } from '@/components/Example'; import { ComponentStyleDisplay } from '@/components/ComponentStyleDisplay'; ## Demo ## Usage Import the ScrollView component. ```jsx file=./examples/DefaultScrollViewExample.tsx ``` ### Horizontal overflow For horizontal scrollbars, set the width of the `ScrollView` smaller than the width of the content. ```jsx file=./examples/ScrollViewHorizontalExample.tsx ``` ### Vertical overflow For vertical scrollbars, set the height of the `ScrollView` smaller than the height of the content. ```jsx file=./examples/ScrollViewVerticalExample.tsx ``` ## Accessibility If your scrollable content does not have any focusable elements, there are additional HTML attributes you can add to your ScrollView to make it more friendly to keyboard users. To create accessible, scrollable regions, you can add a `tabIndex` to the ScrollView to make it keyboard navigable. Additionally, you can add an accessible label to the ScrollView to give extra context about the scrollable content to screen reader users. In the following example, we've used an `aria-label`. Read more about keyboard friendly, scrollable regions from W3.org ```jsx file=./examples/AccessibleScrollViewExample.tsx ``` ## CSS Styling ### Target classes ### Local styling To override styling on a specific View, you can use a class selector or style props. _Using a class selector:_ { "Michaelmas term lately over, and the Lord Chancellor sitting in Lincoln's Inn Hall. Implacable November weather. As much mud in the streets as if the waters had but newly retired from the face of the earth." } ```css /* styles.css */ .my-scrollview { height: 100px; width: 200px; padding: var(--amplify-space-medium); background-color: var(--amplify-colors-blue-10); } ``` ```jsx import { ScrollView } from '@aws-amplify/ui-react'; import './styles.css'; { "Michaelmas term lately over, and the Lord Chancellor sitting in Lincoln's Inn Hall. Implacable November weather. As much mud in the streets as if the waters had but newly retired from the face of the earth." } ``` _Using style props:_ ```jsx file=./examples/ScrollViewStylePropsExample.tsx ```